//
// Created by dddgzc on 2025/1/23.
//

#ifndef ANIMATION_H
#define ANIMATION_H
#include "Atlas.h"
#include "Camera.h"
#include "DrawUtils.h"
#include <functional>

class Animation {
public:
    explicit Animation() = default;
    ~Animation() = default;
    void onUpdate(int delta);
    void onDraw(const Camera& camera, int x, int y) const;
    void setAtlas(Atlas* atlas);

    void reset();
    void setIsLoop(bool isLoop);
    void setInterval(int interval);
    int getIndexFrame() const;
    bool checkFinished() const;
    SDL_Texture* getFrame() const;
    void setOnAnimationFinishedCallback(std::function<void()> callback);

private:
    Atlas* atlas = nullptr; // 图集
    int time = 0; // 计数器
    int frameIdx = 0; // 帧索引
    int interval = 5; // 每一帧的间隔
    bool isLoop = true; // 是否循环播放
    std::function<void()> onAnimationFinishCallback; // 当动画播放结束后回调
};



#endif //ANIMATION_H
